package com.fms.player.ui.common
{
	import com.fms.player.util.GlobalVar;
	
	import flash.events.NetStatusEvent;
	import flash.events.StatusEvent;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	
	import mx.controls.Alert;
	import mx.core.UIComponent;
	
	import spark.components.Group;
	
	
	public class ReceiveStream extends Group
	{
		private var video:Video;
		private var nc:NetConnection;
		private var ns:NetStream;
		private var videoName:String;
		
		public function ReceiveStream(_url:String, _videoName:String)
		{
			super();
			videoName = _videoName;
			nc = new NetConnection();
			nc.connect(_url);
			nc.client = this;
			nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusHandler);
		}
		
		private function onNetStatusHandler(evt:NetStatusEvent):void
		{
			Alert.show("evt.info.code:"+evt.info.code);
			if(evt.info.code == "NetConnection.Connect.Success")
			{
				ns = new NetStream(nc);
				ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusHandler);
				video = new Video();
				video.attachNetStream(ns);
				ns.play(videoName);
				video.x = 20;
				video.y = 20;
				
				var ui:UIComponent = new UIComponent();
				ui.addChild(video);
				ui.width = 500;
				ui.height = 500;
				this.addElement(ui);
			}
		}
		
		public function showmsg(msg:String):void
		{
			Alert.show(msg+"\n");
		}
	}
}